local fengyue = fk.CreateSkill{
    name = "ym2__fengyue",
}
Fk:loadTranslationTable{
    ["ym2__fengyue"] = "锋岳",
    [":ym2__fengyue"] = "出牌阶段限两次，你可与一名角色拼点。若你赢，你摸两张牌。若你输，本次拼点牌加入“锋岳”下次摸牌。然后你展示双方手牌，若你能赢却输，你下次拼点必输。若你能输却赢，你下次拼点必胜。",
    ["@$ym2__fengyue"] = "锋岳",
    ["@@ym2__fengyue-lose"] = "拼点必输",
    ["@@ym2__fengyue-win"] = "拼点必赢",
    ["#ChangePindianResult"] = "由于 %arg，%from 在 %from 和 %to 之间的拼点中 %arg2",
}
fengyue:addEffect("active",{
    max_phase_use_time = 2,
    card_num = 0,
    target_num = 1,
    can_use = function(self, player)
        return not player:isKongcheng() and player:usedSkillTimes(fengyue.name, Player.HistoryPhase) < 2
    end,
    card_filter = Util.FalseFunc,
    target_filter = function(self, player, to_select, selected, selected_cards)
        return #selected == 0 and to_select ~= player and player:canPindian(to_select)
    end,
    on_use = function(self, room, effect)
        local player = effect.from
        local target = effect.tos[1]
        local pindian = player:pindian({target}, fengyue.name)
        if player.dead then return end
        local loser = nil
        if pindian.results[target].winner == player then
            loser = target
            player:drawCards(2,self.name)
        elseif pindian.results[target].winner == target then
            loser = player
            local ids = {}
            table.insert(ids, pindian.fromCard:getEffectiveId())
            table.insert(ids, pindian.results[target].toCard:getEffectiveId())
            if #ids > 0 then
                local mark = player:getTableMark("@$ym2__fengyue")
                table.insertTableIfNeed(mark,ids)
                room:setPlayerMark(player,"@$ym2__fengyue",mark)
                room:moveCardTo(ids,Card.Void,nil,fk.ReasonJustMove,fengyue.name,nil,true,player,nil)
            end
        end
        local cards1, cards2 = player:getCardIds("h"), target:getCardIds("h")
        player:showCards(cards1)
        target:showCards(cards2)
        if loser == player then
            if #table.filter(cards1,function (cardID)
                return Fk:getCardById(cardID).number > pindian.results[target].toCard.number
            end) > 0 then
                room:setPlayerMark(player,"@@ym2__fengyue-lose",1)
            end
        elseif loser == target then
            if #table.filter(cards2,function (cardID)
                return Fk:getCardById(cardID).number > pindian.fromCard.number
            end) > 0 then
                room:setPlayerMark(player,"@@ym2__fengyue-win",1)
            end
        end
    end,
})
fengyue:addEffect(fk.BeforeCardsMove,{
    can_refresh = function (self, event, target, player, data)
        if #player:getTableMark("@$ym2__fengyue") > 0 then
            for _, move in ipairs(data) do
                if move.to == player and move.toArea == Card.PlayerHand and move.moveReason == fk.ReasonDraw  and move.skillName == fengyue.name then
                    return true
                end
            end
        end
    end,
    on_refresh = function (self, event, target, player, data)
        local room = player.room
        local ids = player:getTableMark("@$ym2__fengyue")

        for _, move in ipairs(data) do
            for _, id in ipairs(ids) do
                table.insert(move.moveInfo, {cardId = id, fromArea = room:getCardArea(id)})
            end
        end

        room:setPlayerMark(player,"@$ym2__fengyue",0)
    end,
})
fengyue:addEffect(fk.PindianFinished,{
    can_refresh = function (self, event, target, player, data)
        return (data.from == player or table.contains(data.tos, player)) and (player:getMark("@@ym2__fengyue-win") ~= 0 or player:getMark("@@ym2__fengyue-lose") ~= 0)
    end,
    on_refresh = function (self, event, target, player, data)
        local room = player.room
        for _, to in ipairs(data.tos) do
            if data.from == player then
                if player:getMark("@@ym2__fengyue-lose") ~= 0 then
                    room:setPlayerMark(player,"@@ym2__fengyue-lose",0)
                    data.results[to].winner = to
                end
                if player:getMark("@@ym2__fengyue-win") ~= 0 then
                    room:setPlayerMark(player,"@@ym2__fengyue-win",0)
                    data.results[to].winner = player
                end
            elseif to == player then
                if player:getMark("@@ym2__fengyue-lose") ~= 0 then
                    room:setPlayerMark(player,"@@ym2__fengyue-lose",0)
                    data.results[to].winner = data.from
                end
                if player:getMark("@@ym2__fengyue-win") ~= 0 then
                    room:setPlayerMark(player,"@@ym2__fengyue-win",0)
                    data.results[to].winner = player
                end
            end
            room:sendLog{
                type = "#ChangePindianResult",
                from = data.from.id,
                to = { to.id },
                arg = fengyue.name,
                arg2 = data.results[to].winner == data.from and "pindianwin" or "pindiannotwin",
            }
        end
    end,
})
return fengyue